<div class="main-content">
    <div class="section__content section__content--p20">
        <div class="container-fluid">
            <div class="row m-b-30">
                <div class="col-lg-12">
                    <div class="overview-wrap">
                        <h2 class="title-1">管理组管理</h2>
                        <button class="au-btn au-btn-icon au-btn--blue"  onclick="showedit(0)">
                            <i class="zmdi zmdi-plus"></i>添加管理组</button>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="table-responsive table--no-card m-b-30">
                        <table class="table table-borderless table-striped table-earning">
                            <thead>
                            <tr>
                                <th>角色</th>
                                <th class="td-tools">工具</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            if (sizeof($roles) > 0) {
                                foreach ($roles as $r) {
                                    ?>
                                    <tr>
                                        <td><?php echo $r['rolename']; ?></td>
                                        <td>
                                            <button type="button" class="btn btn-primary btn-sm"  onclick="showedit(<?php echo $r['id']; ?>)" >编辑</button>
                                            <button type="button" class="btn btn-danger btn-sm"  data-toggle="modal" data-target="#confirmModal" onclick="del(<?php echo $r['id']; ?>)">删除</button>
                                        </td>
                                    </tr>
                                    <?php
                                }
                            }
                            ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function showedit(id) {
        if (id == 0) {
            window.location.href = "index.php?r=admin/role/add&id=" + id;
            return;
        }
        window.location.href = "index.php?r=admin/role/showedit&id=" + id;
    }
    function del(id) {
        $("#confirmModal_text").text('确定删除管理员组？');
        $("#confirmModalButton").bind("click",function () {
            $.get('index.php?r=admin/role/del', {id: id}, function (result) {
                if(message(result)){
                    window.location.href = "index.php?r=admin/role/index";
                }
            }, 'json');
        });
    }
</script>